import * as TYPES from "../action_type";
import { get_function, edit_function, search_function,creat_tree } from "../function";

export default function custom(state = {
    data: [],
    edit_data: [],
    manage_data: [],
    manage_EditData: [],
    manageAdd_val: [],
    manage_SaveVal: [],
    manage_Second_SaveVal: [],
    standData: [],
    stand_EditData: [],
    stand_upload:'',
    dynamicData: [],
    dynamic_EditData: [],
    Dynamic_edit_arr: false,
    Dynamic_newArr: [],
    wang: '',
    dataImport_arr: [],
    data_childArr: [],
    dataManagement: [],
    dataManagement_A: [],
    dataManagement_save: [],
    dataManagement_B: [],
    dataManagement_B_see: [],
    content:[],
    content_clo:[],
    secondContent:[],
    content_data:[],
    value: '123213s',

}, action) {
    state = JSON.parse(JSON.stringify(state));
    const { data, edit_data, manage_data, manage_EditData, standData, stand_EditData, dynamicData, dynamic_EditData, dataImport_arr } = state;
    switch (action.type) {
        case TYPES.HOME_GET:
            let { home_data } = action;
            get_function(data, home_data);
            break;
        case TYPES.HOME_EDIT:
            let { save_data } = action;
            edit_function(edit_data, save_data);
            break;
        case TYPES.HOME_SEARCH:
            let { search_data } = action;
            search_function(data, search_data);
            break;
        case TYPES.MANAGEMENT_GET:
            let { management_data } = action;
            get_function(manage_data, management_data);
            break;
        case TYPES.MANAGEMENT_EDIT:
            let { save_num } = action;
            edit_function(manage_EditData, save_num);
            break;
        case TYPES.MANAGEMENT_SEARCH:
            let { search_num } = action;
            search_function(manage_data, search_num);
            break;
        case TYPES.MANAGEMENT_ADD:
            let { add_val } = action;
            get_function(state.manageAdd_val, add_val);
            break;
        case TYPES.MANAGEMENT_EDIT_SAVE:
            let { Save_transfer, second_transfer } = action;
      
            get_function(state.manage_SaveVal, Save_transfer)
            get_function(state.manage_Second_SaveVal, second_transfer)
            break;
        case TYPES.MANAGEMENT_DELETE:
            manage_EditData.splice(0, manage_EditData.length);
            break;
        case TYPES.STANDARD_GET:
            let { stand_data } = action;
            get_function(standData, stand_data)
            break;
        case TYPES.STANDARD_EDIT:
            let { stand_num } = action;
            edit_function(stand_EditData, stand_num);
            break;
        case TYPES.STANDARD_UPLOAD:
            let {upload_pay}=action;
            state.stand_upload=upload_pay;
            break;
        case TYPES.DYNAMIC_GET:
            let { dynamic_data } = action;
            get_function(dynamicData, dynamic_data);
            break;
        case TYPES.DYNAMIC_EDIT:
            let { dynamic_num } = action;
            edit_function(dynamic_EditData, dynamic_num);
            break;
        case TYPES.DYNAMIC_SEARCH:
            let { dynamic_search } = action;
            search_function(dynamicData, dynamic_search);
            break;
        case TYPES.DYNAMIC_WANG:
            let { wang_data } = action;
            state.wang = wang_data;
            break;
        //编辑页面上传图片修改状态
        case TYPES.EDIT_IMG:
            state.Dynamic_edit_arr = false;
            break;
        case TYPES.EDIT_FALSE_IMG:
            state.Dynamic_edit_arr = !state.Dynamic_edit_arr;
            break;
        case TYPES.DATA_IMPORT:
            let { import_data } = action;
            get_function(dataImport_arr, import_data);
            break;
        case TYPES.DATA_SEARCH:
            let { dataSearch_num } = action;
            search_function(dataImport_arr, dataSearch_num);
            break;
        case TYPES.DATA_CHILDREN:
            let { data_child_data } = action;
            get_function(state.data_childArr, data_child_data);
            break;
        case TYPES.DATA_MANAGEMENT_GET:
            let { manageData } = action;
            state.dataManagement = creat_tree(manageData)
            break;
        case TYPES.DATA_MANAGEMENT_SELECT:
            let { manage_select_val } = action;
            state.value = manage_select_val;
            break;
        case TYPES.DATA_MANAGEMENT_SAVE:
            let { manage_save_val } = action;
            state.dataManagement_save = manage_save_val;

            break;

        case TYPES.DATA_MANAGEMENT_SEE:
            let { manage_seeVal } = action;
            if (manage_seeVal.state == true) {
                state.dataManagement_B.splice(0, state.dataManagement_B.length);
                state.dataManagement_B_see=manage_seeVal.new_list;
            } else {
                state.dataManagement_B.splice(0, state.dataManagement_B.length);

                state.dataManagement_B.push(manage_seeVal)
            }
            break;
        case TYPES.DATA_MANAGEMENT_KEY:
            let {pay_key}=action;
            state.dataManagement_save.map((item,index)=>{
                item.key=pay_key[index]
            })
        break;
        case TYPES.DATA_MANAGEMENT_CONTENT:
            let {content_val}=action;
          
            if(content_val.columns!=undefined){
                state.content=content_val.dataSources;
                state.content_clo=content_val.columns;
            }else{
                state.content=content_val
            }
            break;
        case TYPES.MANAGEMENT_SECOND_CONTENT:
            let {second_content}=action;
            
            if(second_content.columns!=undefined){
                state.secondContent=second_content.dataSources;
                state.content_data=second_content.columns
            }else{
                state.secondContent=second_content
            }
            break;
    }
    return state;
}